package com.fhzn.auth.advice;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fhzn.auth.advice.log.LogAdvice;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author fhzn
 */
@Aspect
@Component
public class WebLogAdvice extends LogAdvice {

    public WebLogAdvice(ObjectMapper objectMapper) {
        super(objectMapper);
    }

    @Pointcut("execution(* com.fhzn.auth.web..*.*(..))")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object methodCacheHold(ProceedingJoinPoint pjp) throws Throwable {
        Object target = pjp.getTarget();
        if (target instanceof HandlerInterceptor) {
            return pjp.proceed();
        }
        return super.log(pjp);
    }
}
